<?php


class PublicAction extends Action{


    public function login(){
        $this->display();
    }


    public function checklogin(){
        $name		=	isset($_POST["name"]) ? $_POST["name"] : Cookie::get("name");
        $pwd	=	isset($_POST["pwd"]) ? $_POST["pwd"] : Cookie::get("pwd");
        if(md5($_POST['verify']) != $_SESSION['verify']){
            $this->error("验证码输入错误!");
        }
        //验证用户信息
        $userDao	=	D('Sysadmin');
        $user		=	$userDao->where("name='".$name."' and pwd='".$pwd."'")->find();
        //dump($userDao->getLastSql());
        //验证成功
        if($user){

            //更新登录时间
            //$userDao->setField('UserLastTime',time(),"UserID=".$user['UserID']);
            //记录登陆状态
            Session::set('adminID',$user['id']);
            Session::set('userInfo',$user);
            Cookie::set('name',$name,36000000);

            $group_id = D("Sysadmin")->getField('gid',"id=".$user['id']);
            //dump($group_id);exit;
            $glist = D('Sysadmingroupaccess')->Field("action,method,nid")->where("group_id=$group_id")->findAll();
            //dump($glist);
            Session::set('access',$glist);

            unset($name,$pwd);
            $this->redirect('index','index');
            //验证失败
        }else{
            //跳转到登陆页面
            $this->assign("jumpUrl",__APP__.'/Public/login');
            $this->error('验证失败,请重新登入!');
        }
    }


    public function logout(){
        Session::clear();
        Cookie::delete("email");
        Cookie::delete("password");
        Cookie::clear();

        //$this->redirect("index","Index");
        $this->assign('jumpUrl',__APP__.'/Public/login');
        $this->success('注销成功!');
    }


    public function verify(){
        import("ORG.Util.Image");
        Image::buildImageVerify();
    }


}

?>